<?php
    include 'include/conf.php';


    // if(!(isset($_COOKIE['islogin']) && $_COOKIE['islogin'] == 1)){
    //     echo '<h1>您还未登录,请登录！</h1>';
	// 	echo '<script>setTimeout(()=>{window.location.href="login.php";},2000);</script>';
    //     exit;
    // }
    if(!(isset($_SESSION['islogin']) && $_SESSION['islogin'] == 1)){
        echo '<h1>您还未登录,请登录！</h1>';
		echo '<script>setTimeout(()=>{window.location.href="login.php";},2000);</script>';
        exit;
    }
    $info_type = $db->selectAll('info_type');  //info的信息
    $banner_type = $db->selectAll('bantype');  //轮播图的信息
    $case_type = $db->selectAll('case_type');  //案例信息
    $current_url = pathinfo($_SERVER['PHP_SELF'])['basename'];//获取当前URL
    $admin_name = $_SESSION['username'];    //获取当前用户名
//pre($case_type);die;

    $inf_type = !isset($_GET['info-type']) ? '' : $_GET['info-type'];
    $ban_type = !isset($_GET['banner-type']) ? '' : $_GET['banner-type'];
    $ca_type = !isset($_GET['case-type']) ? '' : $_GET['case-type'];

    if($_GET['logout'] == 1 && isset($_GET['logout'])){
        $logout_time = time();
        $ip = $_SERVER['REMOTE_ADDR'];
        $value = "admin_last_login = '{$logout_time}', admin_reg_ip = '{$ip}'";
        $ad_cond = "WHERE admin_name = '$admin_name'";
        $db->update('admin', $value, $ad_cond);
        $login->logout();
        echo "<script>location.href='login.php';</script>";
    }
    // pre($current_url);
    
?>


<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <title>CMS内容管理系统</title>
    <meta name="keywords" content="Admin">
    <meta name="description" content="Admin">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- Core CSS  -->
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="css/glyphicons.min.css">

    <!-- Theme CSS -->
    <link rel="stylesheet" type="text/css" href="css/theme.css">
    <link rel="stylesheet" type="text/css" href="css/pages.css">
    <link rel="stylesheet" type="text/css" href="css/plugins.css">
    <link rel="stylesheet" type="text/css" href="css/responsive.css">

    <!-- Boxed-Layout CSS -->
    <link rel="stylesheet" type="text/css" href="css/boxed.css">

    <!-- Demonstration CSS -->
    <link rel="stylesheet" type="text/css" href="css/demo.css">

    <!-- Your Custom CSS -->
    <link rel="stylesheet" type="text/css" href="css/custom.css">

    <!-- Core Javascript - via CDN -->
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery-ui.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/uniform.min.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
    <script type="text/javascript" src="js/custom.js"></script>
    
</head>

<body>
    <!-- Start: Header -->
    <header class="navbar navbar-fixed-top" style="background-image: none; background-color: rgb(240, 240, 240);">
        <div class="pull-left"> <a class="navbar-brand" href="#">
                <div class="navbar-logo"><img src="images/logo.png" alt="logo"></div>
            </a> </div>
        <div class="pull-right header-btns">
            <a class="user"><span class="glyphicons glyphicon-user"></span> <?php echo $admin_name; ?></a>
            <a href="?logout=1" class="btn btn-default btn-gradient" type="button"><span class="glyphicons glyphicon-log-out"></span> 退出</a>
        </div>
    </header>
    <!-- End: Header -->

    <!-- Start: Main -->
    <div id="main">
        <!-- Start: Sidebar -->
        <aside id="sidebar" class="affix">
            <div id="sidebar-search">
                <div class="sidebar-toggle"><span class="glyphicon glyphicon-resize-horizontal"></span></div>
            </div>
            <div id="sidebar-menu">
                <ul class="nav sidebar-nav">
                    <li class="<?php if($current_url == 'index.php'){echo 'active';} ?>">
                        <a href="index.php"><span class="glyphicons glyphicon-home"></span><span class="sidebar-title">后台首页</span></a>
                    </li>

<!--                    信息栏-->
                    <li class="<?php if($current_url == 'info_list.php'){echo 'active';} ?>"> <a href="#sideEight" class="accordion-toggle <?php if($current_url == 'info_list.php'){echo 'menu-open';} ?>"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">资讯管理</span><span class="caret"></span></a>
                        <ul class="nav sub-nav" id="sideEight">
                            <li class="<?php if($inf_type == '' && $current_url == 'info_list.php'){echo 'active';} ?>"><a href="info_list.php"><span class="glyphicons glyphicon-record"></span> 所有资讯</a></li>
                            <?php foreach($info_type as $val){ ?>
                                <li class="<?php if($val['info_type_id'] == $inf_type){echo 'active';} ?>"><a href="info_list.php?info-type=<?php echo $val['info_type_id']; ?>"><span class="glyphicons glyphicon-record"></span> <?php echo $val['info_type_name']; ?></a></li>
                            <?php } ?>                            
                        </ul>
                    </li>
                    <li>
                        <a href="article_list.php"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">文章分类管理</span></a>
                    </li>

<!--                    轮播图栏-->
                    <li class="<?php if($current_url == 'banner_list.php'){echo 'active';} ?>"> <a href="#sideEight" class="accordion-toggle <?php if($current_url == 'banner_list.php'){echo 'menu-open';} ?>"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">轮播图管理</span><span class="caret"></span></a>
                        <ul class="nav sub-nav" id="sideEight">
                            <li class="<?php if($ban_type == '' && $current_url == 'banner_list.php'){echo 'active';} ?>"><a href="banner_list.php"><span class="glyphicons glyphicon-record"></span> 所有轮播图</a></li>
                            <?php foreach($banner_type as $val){ ?>
                                <li class="<?php if($val['btype_id'] == $ban_type){echo 'active';} ?>"><a href="banner_list.php?banner-type=<?php echo $val['btype_id']; ?>"><span class="glyphicons glyphicon-record"></span> <?php echo $val['btype_name']; ?></a></li>
                            <?php } ?>                            
                        </ul>
                    </li>

<!--                    案例分类管理-->
                    <li class="<?php if($current_url == 'case_type.php'){echo 'active';} ?>">
                        <a href="case_type.php"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">案例分类管理</span></a>
                    </li>
<!--                    案例栏-->
                    <li class="<?php if($current_url == 'cases.php'){echo 'active';} ?>"> <a href="#sideEight" class="accordion-toggle <?php if($current_url == 'cases.php'){echo 'menu-open';} ?>"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">案例管理</span><span class="caret"></span></a>
                        <ul class="nav sub-nav" id="sideEight">
                            <li class="<?php if($ca_type == '' && $current_url == 'cases.php'){echo 'active';} ?>"><a href="cases.php"><span class="glyphicons glyphicon-record"></span> 所有案例</a></li>
                            <?php foreach($case_type as $val){ ?>
                                <li class="<?php if($val['case_type_id'] == $ca_type){echo 'active';} ?>"><a href="cases.php?case-type=<?php echo $val['case_type_id']; ?>"><span class="glyphicons glyphicon-record"></span> <?php echo $val['case_type_name1']; ?></a></li>
                            <?php } ?>
                        </ul>
                    </li>

                    <!--                    服务分类管理-->
                    <li class="<?php if($current_url == 'service_type.php'){echo 'active';} ?>">
                        <a href="service_type.php"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">服务分类管理</span></a>
                    </li>
<!--                    服务栏-->
                    <li class="<?php if($current_url == 'service.php'){echo 'active';} ?>"> <a href="#sideEight" class="accordion-toggle <?php if($current_url == 'service.php'){echo 'menu-open';} ?>"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">服务管理</span><span class="caret"></span></a>
                        <ul class="nav sub-nav" id="sideEight">
                            <li class="<?php if($serv_type == '' && $current_url == 'service.php'){echo 'active';} ?>"><a href="service.php"><span class="glyphicons glyphicon-record"></span> 所有服务</a></li>
                            <?php foreach($serv_type as $val){ ?>
                                <li class="<?php if($val['serv_type_id'] == $serv_type){echo 'active';} ?>"><a href="service.php?server-type=<?php echo $val['serv_type_id']; ?>"><span class="glyphicons glyphicon-record"></span> <?php echo $val['serv_type_name']; ?></a></li>
                            <?php } ?>
                        </ul>
                    </li>

<!--                    关于我们-->
                    <li class="<?php if($current_url == 'about.php'){echo 'active';} ?>">
                        <a href="about.php"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">关于我们</span></a>
                    </li>

                    <!-- 标语-->
                    <li class="<?php if($current_url == 'slogan.php'){echo 'active';} ?>">
                        <a href="slogan.php"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">标语管理</span></a>
                    </li>
                    
                    <li>
                        <a href="user_list.php"><span class="glyphicons glyphicon-list"></span><span class="sidebar-title">系统管理员</span></a>
                    </li>
                </ul>
            </div>
        </aside>
        <!-- End: Sidebar -->